﻿using UnityEngine;
using System.Collections;

public class CalculateSimilary : MonoBehaviour 
{
	public HumanProperty Human;
	public HumanProperty HumanTarget;
	public UILabel LabelSimilary;
	public float SliderSpeed = 0.5f;

	public UISlider HeadSlider;
	public UISlider ChestSlider;
	public UISlider HandSlider;
	public UISlider LegSlider;
	public UISlider SkinSlider;
	
	void Awake()
	{
		HeadSlider = this.transform.Find("HeadBar").GetComponent<UISlider>();
		ChestSlider = this.transform.Find("ChestBar").GetComponent<UISlider>();
		HandSlider = this.transform.Find("HandBar").GetComponent<UISlider>();
		LegSlider = this.transform.Find("LegBar").GetComponent<UISlider>();
		SkinSlider = this.transform.Find("SkinBar").GetComponent<UISlider>();
	}

	public void Calculate()
	{
		float f1 =  Mathf.Abs((float)Human.BodyWidth - (float)HumanTarget.BodyWidth) / ((float)HumanTarget.BodyWidth);
		float f2 =  Mathf.Abs((float)Human.BodyHeight - (float)HumanTarget.BodyHeight) / ((float)HumanTarget.BodyHeight);
		float f3 =  Mathf.Abs((float)Human.HeadWidth - (float)HumanTarget.HeadWidth) / ((float)HumanTarget.HeadWidth);
		float f4 =  Mathf.Abs((float)Human.HeadHeight - (float)HumanTarget.HeadHeight) / ((float)HumanTarget.HeadHeight);
		float f5 =  Mathf.Abs((float)Human.HandLength - (float)HumanTarget.HandLength) / ((float)HumanTarget.HandLength);
		float f6 =  Mathf.Abs((float)Human.LegLength - (float)HumanTarget.LegLength) / ((float)HumanTarget.LegLength);
	
		print (f1);
		print (f2);
		print (f3);
		print (f4);
		print (f5);
		print (f6);

		int average = 100 - (int)((f1 + f2 + f3 + f4 + f5 + f6)*100) / 6;

		LabelSimilary.text = "相似度"+average.ToString ()+"%";

		ShowSliderAnimation ((f1+f2)/2f, (f3+f4)/2f, f5, f6, 1f );
	}

	void ShowSliderAnimation(float Body, float Head, float Hand, float Leg, float color)
	{
		HeadSlider.value = 1f-Head;
		ChestSlider.value = 1f-Body;
		HandSlider.value = 1f-Hand;
		LegSlider.value = 1f-Leg;
		SkinSlider.value = color;

	}
}
